﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ELTE.TFEG.Hough.Controls
{
    /// <summary>
    /// Interaction logic for ZoomableImage.xaml
    /// </summary>
    public partial class ZoomableImage : UserControl
    {
        public bool Selected { get; set; }

        public ZoomableImage()
        {
            InitializeComponent();
        }

        public ZoomableImage(BitmapImage image)
        {
            InitializeComponent();
            this.SetImage(image);
        }

        public void SetImage(Uri imageUri)
        {
            this.imgToShow.Source = new BitmapImage(imageUri);
        }

        public void SetImage(BitmapImage image)
        {
            this.imgToShow.Source = image;
        }

        private ScaleTransform GetScale()
        {
            TransformGroup transformGroup = (TransformGroup)this.imgToShow.RenderTransform;
            ScaleTransform transform = (ScaleTransform)transformGroup.Children[0];
            return transform;
        }

        public void SetZoom(double zoomLevel)
        {
            ScaleTransform transform = GetScale();
            transform.ScaleX += zoomLevel;
            transform.ScaleY += zoomLevel;
            //this.imgToShow.Width;
        }

        public void ToggleSelect()
        {
            if (this.borderImg.BorderBrush == Brushes.Green)
            {
                this.borderImg.BorderBrush = Brushes.GreenYellow;
            }
            else
            {
                this.borderImg.BorderBrush = Brushes.Green;
            }
            Selected = !Selected;
        }

        private void imgToShow_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            try
            {
                double zoom = e.Delta > 0 ? .2 : -.2;
                SetZoom(zoom);
            }
            catch (Exception ex)
            {
                
            }
            
        }
    }
}
